package com.tigerhhzz.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author tigerhhzz
 * @date 2023/4/16 11:29
 */
@Configuration
public class GateWayConfig {

    /*
    * 配置了一个id为route-name的路由规则
    * 当访问地址http://localhost:9527/guonei时自动转发到地址：http://news.baidu.com/guonei
    * */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route("path_route",r->r.path("/guonei").uri("http://news.baidu.com/guonei"));
        routes.route("path_route1",r->r.path("/guoji").uri("http://news.baidu.com/guoji"));
        return routes.build();
    }

    //@Bean
    //public RouteLocator customRouteLocator1(RouteLocatorBuilder builder) {
    //    RouteLocatorBuilder.Builder routes = builder.routes();
    //    routes.route("path_route2",r->r.path("/guoji").uri("http://news.baidu.com/guoji"));
    //    return routes.build();
    //}
}

